package com.cnplan.service.impl;

import com.cnplan.entity.ArcFile;
import com.cnplan.mapper.ArcFileMapper;
import com.cnplan.service.ArcFileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ArcFileServiceImpl implements ArcFileService {

    @Autowired
    private ArcFileMapper arcFileMapper;

    @Override
    public PageInfo findArcFile(Map map) {
        if(!map.containsKey("pageNo")){
            map.put("pageNo",1);
        }
        if(!map.containsKey("pageSize")){
            map.put("pageSize",8);
        }
        StringBuffer sb=new StringBuffer();
        String fileName=map.containsKey("fileName")?map.get("fileName").toString():null;
        if(fileName!=null){
            String[] gNameArray=fileName.split(" ");
            for (String str:gNameArray) {
                sb.append(" and file_name like '%"+str.trim()+"%'");
            }
        }
        PageHelper.startPage(Integer.parseInt(map.get("pageNo").toString()),
                Integer.parseInt(map.get("pageSize").toString()));
        List<ArcFile> List=arcFileMapper.getArcFile(map.get("arcNum").toString(),sb+"");
        for (ArcFile arcFile:List) {
            arcFile.setFileName(arcFile.getFileName().replace("'",""));
        }
        PageInfo pageInfo = new PageInfo(List);
        return pageInfo;
    }

    @Override
    public ArcFile findByArcFileNum(String arcNum, String fileNum) {
        return arcFileMapper.findByFileNum(arcNum,Integer.parseInt(fileNum));
    }

    @Override
    public ArcFile findByArcNum(String arcNum) {
        return arcFileMapper.findByarcNum(arcNum);
    }

}
